<?php

namespace App\Http\Controllers;

use App\Model\QualityCheck;
use App\Model\QualityCheckChild;
use Illuminate\Http\Request;
use App\Http\Resources\QualityCheck as QualityCheckResource;
use App\Http\Resources\QualityCheckChild as QualityCheckChildResource;

class MemberController extends ApiController
{
    //
    public function myinfo()
    {
        $data = auth()->user();
        return $this->success([
            'EmpID'=>$data['EmpID'],
            'LoginUser'=>$data['LoginUser'],
        ]);
    }

    /**
     * 质检单列表
     */
    public function QCList(Request $request){

        $keyword = $request->get('keyword');
        $page = $request->get('page',1);
        $size = $request->get('size',10);

        $query = QualityCheck::query();
        if($keyword){
            $query->where(function($query) use ($keyword){
                $query->where('QCRptNo','=',$keyword)->orWhere('BillNo','=',$keyword)->orWhere('OwnerName','like','%'.strtoupper($keyword).'%');
            });
        }

        $data = $query->offset(($page-1)*$size)->limit($size)->get();
        return $this->success(QualityCheckResource::collection($data));
    }

    public function QCInfo($fid){
        $info = QualityCheck::query()->with('child')->findOrFail($fid);
        return $this->success(new QualityCheckResource($info));
    }

    public function QCDtlInfo($fid){
        $info = QualityCheckChild::query()->findOrFail($fid);
        return $this->success(new QualityCheckChildResource($info));
    }
}
